﻿@model CMS_User
<div class="easyui-layout" data-options="fit:true">
    <!-- Begin of toolbar -->
    <div id="wu-toolbar">
        <div class="wu-toolbar-button">
            <a href="#" class="easyui-linkbutton" iconcls="icon-add" onclick="openAdd()" plain="true">添加</a>
            <a href="#" class="easyui-linkbutton" iconcls="icon-edit" onclick="openEdit()" plain="true">修改</a>
            <a href="#" class="easyui-linkbutton" iconcls="icon-remove" onclick="remove()" plain="true">删除</a>
            <a href="#" class="easyui-linkbutton" iconcls="icon-reload" onclick="reload()" plain="true">刷新</a>
        </div>
        <div class="wu-toolbar-search">
            <label>是否为管理员：</label>
            <select id="select_admin" class="easyui-combobox" panelheight="auto" style="width:100px">
                <option value="3">请选择...</option>
                <option value="true">是</option>
                <option value="false">否</option>
            </select>
            <label>姓名：</label><input id="txt_name" class="wu-text" style="width:100px">
            <a href="javascript:void(0)" onclick="loadlist();" class="easyui-linkbutton" iconcls="icon-search">开始检索</a>
        </div>
    </div>
    <!-- End of toolbar -->
    <table id="wu-datagrid" toolbar="#wu-toolbar"></table>
</div>
<!-- Begin of easyui-dialog -->
<!-- End of easyui-dialog -->

<script type="text/javascript">
    /**
    * Name 添加记录
    */
    function add() {
        $('#wu-form-2').form('submit', {
            url: '',
            success: function (data) {
                if (data) {
                    $.messager.alert('信息提示', '提交成功！', 'info');
                    $('#wu-dialog-2').dialog('close');
                }
                else {
                    $.messager.alert('信息提示', '提交失败！', 'info');
                }
            }
        });
    }
    /**
    * Name 打开添加窗口
    */
    function openAdd() {
        window.top.addTab("添加用户", "openAdd", "icon-user-add");
    }

    //刷新页面
    function reload() {
        window.location.reload();
    }

    /**
    * Name 打开修改窗口
    */
    function openEdit(id) {
        if (!id) {
            var items = $('#wu-datagrid').datagrid('getSelections');
            if (!items || items.length == 0) { $.messager.alert("提示", "请先选择需要修改的用户！"); return; }
            if (items.length > 1) { $.messager.alert("提示", "只能选择一位用户"); return; }
            id = items[0].uid;
        }
        window.top.addTab("修改用户", "/HT/HouTai/openEdit/" + id, "icon-user-edit");
    }

    /**
    * Name 删除记录
    */
    function remove() {

}

     /* $.post("/HT/HouTai/remove", {*/
            @*id:'@Model.uid',*@
        //}), function (r) {
        //    reload();
        //    };

    /**
    * Name 分页过滤器
    */
    function pagerFilter(data) {
        if (typeof data.length == 'number' && typeof data.splice == 'function') {// is array
            data = {
                total: data.length,
                rows: data
            }
        }
        var dg = $(this);
        var opts = dg.datagrid('options');
        var pager = dg.datagrid('getPager');
        pager.pagination({
            onSelectPage: function (pageNum, pageSize) {
                opts.pageNumber = pageNum;
                opts.pageSize = pageSize;
                pager.pagination('refresh', { pageNumber: pageNum, pageSize: pageSize });
                dg.datagrid('loadData', data);
            }
        });
        if (!data.originalRows) {
            data.originalRows = (data.rows);
        }
        var start = (opts.pageNumber - 1) * parseInt(opts.pageSize);
        var end = start + parseInt(opts.pageSize);
        data.rows = (data.originalRows.slice(start, end));
        return data;
    }


    $(function () {
        /**
        * 用户列表Datagrid控件
        */
        $('#wu-datagrid').datagrid({
            method: 'get',
            url: '/HT/HouTai/UserData',
            rownumbers: true,
            singleSelect: false,
            pageList: [5, 10, 15, 20, 30],
            pageSize: 5,
            pagination: true,
            //multiSort: true,
            fitColumns: true,
            fit: true,
            columns: [[
                { field: 'ck', checkbox: true },
                { field: 'uid', title: '编号', width: 100, sortable: true },
                { field: 'uname', title: '用户名', width: 180, sortable: true, },
                { field: 'upwd', title: '密码', width: 100 },
                { field: 'nname', title: '昵称', width: 100 },
                { field: 'mobile', title: '手机号', width: 100 },
                { field: 'face', title: '头像', width: 100 },
                { field: 'admin', title: '是否为管理员', width: 100 }
            ]]
        });
    });

    //按条件重新查询
    function loadlist() {
        $('#wu-datagrid').datagrid("load", {
            uname: $("#txt_name").val(),
            admin: $(".easyui-combobox").val()
        });
    }
</script>
